package com.lanou.service.impl;

import com.lanou.entity.Page;
import com.lanou.entity.Person;
import com.lanou.mapper.PersonMapper;
import com.lanou.service.PersonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author 姚云鹏
 * Create at: 2018/6/19 11:25
 */
@Service
@Transactional(readOnly = true)
public class PersonServiceImpl implements PersonService {
    @Autowired
    private PersonMapper personMapper;

    @Override
    public List<Person> findAll() {
        return personMapper.findAll();
    }

    @Override
    @Transactional(readOnly = false)
    public Person add(Person person) {
        personMapper.insert(person);

//        int a = 1/0;

        return personMapper.findById(person.getId());
    }

    @Override
    public List<Person> findByPage(Page page) {
        return personMapper.findByPage(page);
    }

    @Override
    public long countAll() {
        return personMapper.countAll();
    }
}
